package tragame.game;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import tragame.interfaces.IUnit;

public class Unit extends UnicastRemoteObject implements IUnit{

	private static final long serialVersionUID = 1L;
	
	public RaceType race;
	public enum RaceType{
		Humain, Elf, Orc;
		public RaceType getRaceType() {
			switch(this) {
				case Humain:
					return RaceType.Humain;
				case Elf:
					return RaceType.Elf;
				default:
					return RaceType.Orc;
			}
		}
	}
	public UnitType type;
	public enum UnitType{
		Attaquant, Defenseur, Eclaireur, Cavalerie, Chef, Colon;
		public UnitType getUnitType() {
			switch(this) {
				case Attaquant:
					return UnitType.Attaquant;
				case Defenseur:
					return UnitType.Defenseur;
				case Eclaireur:
					return UnitType.Eclaireur;
				case Cavalerie:
					return UnitType.Cavalerie;
				case Chef:
					return UnitType.Chef;
				default:
					return UnitType.Colon;
			}
		}
	}
	
	private int costWood;
	private int costSoil;
	private int costIron;
	private int costFood;
	private int formationTime;
	
	private int attack;
	private int defense;
	private int speed;
	
	public Unit(UnitType type, RaceType race) throws RemoteException{
		this.race = race;
		this.type = type;
		initializeWithTypeAndRace(type, race);
	}
	
   
   private void initializeCost(int costWood, int costSoil, int costIron, int costFood, int formationTime){
	   this.costWood=costWood;
	   this.costSoil=costSoil;
	   this.costIron=costIron;
	   this.costFood=costFood;
	   this.formationTime=formationTime;
   }
   
   private void initializeStat(int attack, int defense, int speed){
	   this.attack=attack; 
	   this.defense=defense;
	   this. speed= speed;
	   
   }
   
	private void initializeWithTypeAndRace(UnitType type, RaceType race) {
		switch(type){
			case Chef:
				switch(race){
					case Humain:
						initializeCost(30750,27200,45000,37500,120);
						initializeStat(50,40,4);
					break;
					case Elf:
						initializeCost(30750, 45400, 31000, 37500, 120 );
						initializeStat(40,50,5);
					break;
					default:
						initializeCost(35500, 26600, 25000, 27200 ,120);
						initializeStat(40,60,4);
					break;
				}
				break;
			case Attaquant:
				switch(race){
					case Humain:
						initializeCost(150,160,210,80,60);
						initializeStat(70,40,7);
					break;
					case Elf:
						initializeCost(140 ,150, 185, 60, 60 );
						initializeStat(65,35,6);
					break;
					default:
						initializeCost(130, 120, 170, 70 ,60);
						initializeStat(60,30,6);
					break;
				}
				break;
			case Cavalerie:
				switch(race){
					case Humain:
						initializeCost(550,640,800,180,80);
						initializeStat(180,80,10);
					break;
					case Elf:
						initializeCost(500, 620, 675, 170, 80 );
						initializeStat(140,50,13);
					break;
					default:
						initializeCost(450, 515, 480, 80 ,80);
						initializeStat(150,50,9);
					break;
				}
				break;
			case Defenseur:
				switch(race){
					case Humain:
						initializeCost(100,130,160,70,100);
						initializeStat(30,65,5);
					break;
					case Elf:
						initializeCost(100 ,130, 55 ,30 ,100);
						initializeStat(15, 40, 7);
					break;
					default:
						initializeCost(145, 70, 85, 40,100 );
						initializeStat(10,35,7);
					break;
				}
				break;
			case Colon:
				switch(race){
					case Humain:
						initializeCost(100,130,160,70,100); //a modif
						initializeStat(30,65,5);
					break;
					case Elf:
						initializeCost(100 ,130, 55 ,30 ,100); //a modif
						initializeStat(15, 40, 7);
					break;
					default:
						initializeCost(145, 70, 85, 40,100 ); //a modif
						initializeStat(10,35,7);
					break;
				}
				break;		
			default:
				switch(race){
					case Humain:
						initializeCost(140, 160, 20, 40,90 );
						initializeStat(0,20,16);
					break;
					case Elf:
						initializeCost(170 ,150, 20, 40,90 );
						initializeStat(0, 20, 17);
					break;
					default:
						initializeCost(160 ,100 ,50, 50 ,90);
						initializeStat(0,10,9);
					break;
				}				
			
		}
	}
	
	public String getName(){
		return this.type.toString();
	}
	
	/**
	 * get the attack level of the unit
	 * @return the attack level
	 */	
   public int getAttack(){
	   return this.attack;

   }
   /**
	 * get the defense level of the unit
	 * @return the defense level
	 */
   
   
   public int getDefense(){
	   return this.defense;
	   
   }
   /**
	 * get the speed unit: number of squares per hour
	 * @return the speed of the unit
	 */
   public int getSpeed(){
	   return this.speed;
   }

	public int getFormationTime() {
		return this.formationTime;
	}
	
	/**
	 * get the necessary amount of food to built the building
	 * @return the amount of food
	 */
	public int getCostFood() {
		return this.costFood;
	}
	
	/**
	 * get the necessary amount of iron to built the building
	 * @return the amount of iron
	 */
	public int getCostIron() {
		return this.costIron;
	}
	
	/**
	 * get the necessary amount of soil to built the building
	 * @return the amount of soil
	 */
	public int getCostSoil() {
		return this.costSoil;
	}
	
	/**
	 * get the necessary amount of wood to built the building
	 * @return the amount of wood
	 */
	public int getCostWood() {
		return this.costWood;
	}  
}
      
   
   
   
   
   
   
